import { AdManager } from "./ads/AdManager";
import { BUNDLE_TYPE_ENUM } from "./base/EnumIndex";
import { Tools } from "./common/Tools";
import { AudioManager } from "./manager/AudioManager";
import { NetworkManager } from "./manager/NetworkManager";
import { UIManager } from "./manager/UIManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class GameScene extends cc.Component {
    onLoad() {
        Tools.storageKey = window["selectGame"] + "_v1.0.0"

        AdManager.initAds();

        Tools.updateResolution();

        NetworkManager.initNetwork();
        AudioManager.initStorage();
        // cc.director.getPhysicsManager().enabled = false;
    }

    protected start(): void {
        this.updateBg();
        if (AdManager.isShowFlash()) {
            UIManager.ins.showUI("flashUI", BUNDLE_TYPE_ENUM.MAIN);
            this.scheduleOnce(() => {
                UIManager.ins.close();
                UIManager.ins.showUI("loadUI", BUNDLE_TYPE_ENUM.MAIN);
            }, 3);
        } else {
            UIManager.ins.showUI("loadUI", BUNDLE_TYPE_ENUM.MAIN);
        }
    }

    async updateBg() {
        // let bg = this.node.getChildByName("bg").getComponent(cc.Sprite);
        // bg.spriteFrame = await ResManager.ins.loadRes(`texture/${AdManager.gameType}`, cc.SpriteFrame);
    }
    protected onDestroy(): void {
        this.unscheduleAllCallbacks();
    }
}